<?php
namespace BoxAdmin\Controller;

use Think\Controller;

class IndexController extends CommonController
{
    /**
     * [index 桌面首页]
     * @return [type] [description]
     */
    public function _initialize()
    {
        parent::_initialize();
        $this->user = BoxModel('system_store_user');
        $this->memuNav = "pass";
    }

    public function index()
    {
        $this->jump("", "/BoxAddon/UserAnalysis/Index/index");

    }


    /**
     * [pass 修改密码页]
     * @return [type] [description]
     */
    public function pass()
    {
        $this->display();
    }

    public function checkoldpass()
    {
        $oldpass = I('oldpass');
        $user = $this->user->where(array('id' => session('admin_id')))->find();
        if ($user['password'] != md5($oldpass)) {
            echo json_encode(array(
                'valid' => false,
            ));
        } else {
            echo json_encode(array(
                'valid' => true,
            ));
        }
    }

    public function passdo()
    {
        $newpass = I('post.newpass');
        $cofpass = I('post.cofpass');
        if ($newpass != $cofpass) {
            $this->jump('两次密码输入不一致！');
        }
        $info = $this->_upload("/admin_headico/");
        if ($info) {
            $data['img'] = $info['img']['savepath'] . $info['img']['savename'];
        }
        if ($newpass) {
            $data['password'] = encrypt($newpass);
        }
        $this->user->where(array('id' => session('admin_id')))->save($data);
        // D('Log')->addLogs(session('user_name'),'修改密码');
        $this->jump('密码修改成功', U('Index/pass'));
    }


    public function set_order()
    {
        $model = I("model");
        $where = array(
            I('key') => I('key_value'),
        );
        $row = array(
            'order_by' => I('value'),
        );

        $r = BoxModel($model)->where($where)->save($row);
        if ($r) {
            echo 1;
        } else {
            dump(BoxModel($model));
        }
        //  dump(BoxModel($model));
    }
}

?>